package sudoku

import (
	"strconv"
)

// AnswerRes is the result type of sudoku scoreCalculator
type AnswerRes struct {
	Score        int
	Progress     float64
	ConflictElem GridType
	ValidElem    GridType

	finished bool
}

// IsFinished check whether answer is finished
func (a *AnswerRes) IsFinished() bool {
	return a.finished
}

// CalculateScore calculates score
func CalculateScore(checkRes CheckResType) AnswerRes {
	res := AnswerRes{
		ConflictElem: checkRes.ConflictElem,
		ValidElem:    checkRes.ValidElem,
		finished:     false,
	}

	if checkRes.Status == SValid {
		res.finished = true
	}

	const winRate = 10
	const loseRate = 10
	// caculate all valid elem
	res.Score += winRate * checkRes.ValidElem.Size()
	res.Score -= winRate * checkRes.ConflictElem.Size()
	if checkRes.ToFilledSize <= 0 || checkRes.ToFilledSize > 81 {
		panic("Invalid To FilledSize: " + strconv.Itoa(checkRes.ToFilledSize))
	}
	res.Progress = (float64(checkRes.ValidElem.Size()) / float64(checkRes.ToFilledSize)) * 100

	return res
}
